<%@ page import="java.util.Date" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>合作商管理</title>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">
    <link rel="stylesheet" href="${ctx}/css/ui/system/member/member_list.css">
    <%@include file="../../include/commonFile.jsp" %>
</head>
<body>
<!--头部-->
<%@include file="../../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <form class="layui-form" action="${ctx}/system/member/partnerList.do" id="myForm" method="post">
                <input type="hidden" name="pageNo" id="pageNo"/>
                <input type="hidden" id="from" value="${from}"/>
                <input type="hidden" id="authorizationSuccess"
                       value="<c:choose><c:when test="${grantor != null}">1</c:when>
                        <c:otherwise>0</c:otherwise></c:choose>"/>
                <div class="f-search-bar">
                    <div class="search-container">
                        <ul class="search-form-content">
                            <li class="form-item-inline"><label class="search-form-lable">昵称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="realname" autocomplete="off" class="layui-input"
                                           value="${member.realname}" placeholder="请输入查询昵称">
                                </div>
                            </li>
                            <li class="form-item-inline"><label class="search-form-lable">&nbsp;&nbsp;账号</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="username" autocomplete="off" class="layui-input"
                                           value="${member.username}" placeholder="请输入查询账号">
                                </div>
                            </li>
                            <li class="form-item-inline"><label class="search-form-lable">客户电话</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="customerPhone" autocomplete="off" class="layui-input"
                                           value="${member.customerPhone}" placeholder="请输入查询客户电话">
                                </div>
                            </li>
                            <li class="form-item-inline"><label class="search-form-lable"></label>
                            </li>
                            <li class="form-item-inline"><label class="search-form-lable"></label>
                            </li>
                        </ul>
                        <ul class="search-form-content">
                            <li class="form-item-inline"><label class="search-form-lable">状态</label>
                                <div class="layui-input-inline">
                                    <select name="maturityStatus">
                                        <option value="">全部</option>
                                        <option value="1" ${maturityStatus == 1 ? 'selected="selected"' : ''}>使用中
                                        </option>
                                        <option value="2" ${maturityStatus == 2 ? 'selected="selected"' : ''}>已到期
                                        </option>
                                    </select>
                                </div>
                            </li>
                            <li class="form-item-inline"><label class="search-form-lable">合作商类型</label>
                                <div class="layui-input-inline">
                                    <select name="partnerType">
                                        <option value="">全部</option>
                                        <option value="0" ${partnerType == 0 ? 'selected="selected"' : ''}>系统客户</option>
                                        <option value="1" ${partnerType == 1 ? 'selected="selected"' : ''}>大客户</option>
                                        <option value="2" ${partnerType == 2 ? 'selected="selected"' : ''}>地接客户</option>
                                        <option value="3" ${partnerType == 3 ? 'selected="selected"' : ''}>运营客户</option>
                                        <option value="4" ${partnerType == 4 ? 'selected="selected"' : ''}>注册客户</option>
                                    </select>
                                </div>
                            </li>
                            <li class="form-item-inline"><label class="search-form-lable"></label>
                            </li>
                            <li class="form-item-inline"><label class="search-form-lable"></label>
                            </li>
                            <li class="form-item-inline"><label class="search-form-lable"></label>
                            </li>
                            <li class="form-item-inline"><label class="search-form-lable"></label>
                            </li>
                            <li class="form-item-inline"><label class="search-form-lable"></label>
                            </li>
                        </ul>
                        <ul class="search-form-content">
                            <li class="form-item"><label class="search-form-lable">套餐角色</label>
                                <div class="check-btn-inner">
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),'','#myForm')" ${empty sysRoleId ? 'class="active"' : ''}>全部</a>
                                    <c:forEach var="sysRole" items="${sysRoles}">
                                        <a href="javascript:void(0);"
                                           onclick="setTimeType($(this),'${sysRole.id}','#myForm')" ${sysRoleId == sysRole.id ? 'class="active"' : ''}>${sysRole.name}</a>
                                    </c:forEach>
                                    <input type="hidden" name="sysRoleId" value="${sysRoleId}"/>
                                </div>
                            </li>
                        </ul>
                        <ul class="search-form-content">
                            <li class="form-item"><label class="search-form-lable">注册时间</label>
                                <div class="check-btn-inner" id="timeType">
                                    <a id="all" href="javascript:void(0);"
                                       onclick="setTimeType($(this),0,'#myForm')" ${empty input.timeType || input.timeType == 0 ? 'class="active"' : ''}>全部</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),1,'#myForm')" ${input.timeType == 1 ? 'class="active"' : ''}>今天</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),2,'#myForm')" ${input.timeType == 2 ? 'class="active"' : ''}>本周内</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),3,'#myForm')" ${input.timeType == 3 ? 'class="active"' : ''}>本月内</a>
                                    <input type="hidden" name="timeType" value="${input.timeType}"/>
                                </div>
                                <div class="layui-inline">
                                    <div class="layui-input-inline">
                                        <input class="layui-input" type="text" name="createStart"
                                               value="${input.createStart}" placeholder="开始日">
                                    </div>
                                    -
                                    <div class="layui-input-inline">
                                        <input class="layui-input" type="text" name="createEnd"
                                               value="${input.createEnd}" placeholder="截止日">
                                    </div>
                                </div>
                            </li>
                            <li class="form-item-inline">
                                <div class="sub-btns">
                                    <a class="layui-btn layui-btn-danger"
                                       href="javascript:submitFunction('#myForm')">查询</a>
                                    <a class="layui-btn layui-btn-normal"
                                       href="javascript:resetFunction('#myForm')">重置</a>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
            </form>
            <div class="list-content">
                <ul class="num">
                    <div class="l">
                        <li style="cursor: pointer;" class="r">
                            <a class="layui-btn layui-btn-danger layui-btn-sm" id="btnSuccessExport">导出机构订单数据EXCEL</a>
                        </li>
                    </div>
                    <p class="cl"></p>
                </ul>
                <div class="cl">
                    <table class="layui-table" lay-size="sm">
                        <colgroup>
                            <col width="13%">
                            <col width="150">
                            <col width="15%">
                            <col width="130">
                            <col width="100">
                            <col width="90">
                            <col width="100">
                            <col width="100">
                            <col width="130">
                            <col width="80">
                            <col>
                        </colgroup>
                        <thead>
                        <tr>
                            <th>昵称</th>
                            <th>账号</th>
                            <th>公司全称</th>
                            <th>客户姓名</th>
                            <th>客户电话</th>
                            <th>合作商类型</th>
                            <th>签约人</th>
                            <th>签约时间</th>
                            <th>到期时间</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach var="member" items="${members}" varStatus="varStatus">
                            <tr>
                                <td class="table-member"
                                    onclick="openDialogShow('合作商信息','${ctx}/system/member/getPartnerInfo.do?id=${member.id}','450px','680px')">
                                    <div class="member-cell">
                                        <div class="member-logo common-img">
                                            <img src="<c:if test="${member.logo != null}">${member.logo}?imageMogr2/auto-orient/crop/126x126</c:if>"
                                                 alt="" onerror="txz.errImg(this)" onload="txz.imgLoad(this)">
                                        </div>
                                        <div class="member-name ellipsis-1"><a class="blue" title="${member.realname}"
                                                                               href="javascript:void(0);">${member.realname}</a>
                                        </div>
                                    </div>
                                </td>
                                <td>${member.username}</td>
                                <td>${member.company}</td>
                                <td>${member.fullname}</td>
                                <td>${member.customerPhone}</td>
                                <td>
                                    <c:choose>
                                        <c:when test="${empty member.partnerType || member.partnerType == 0}">
                                            系统客户
                                        </c:when>
                                        <c:when test="${not empty member.partnerType && member.partnerType == 1}">
                                            <span class="green">大客户</span>
                                        </c:when>
                                        <c:when test="${not empty member.partnerType && member.partnerType == 2}">
                                            <span style="color: coral">地接客户</span>
                                        </c:when>
                                        <c:when test="${not empty member.partnerType && member.partnerType == 3}">
                                            <span style="color: darkolivegreen">运营客户</span>
                                        </c:when>
                                        <c:when test="${not empty member.partnerType && member.partnerType == 4}">
                                            <span style="color: darkolivegreen">注册客户</span>
                                        </c:when>
                                    </c:choose>
                                </td>
                                <td>${member.contractor}</td>
                                <td><fmt:formatDate value="${member.signingTime}" pattern="yyyy-MM-dd"/></td>
                                <td><fmt:formatDate value="${member.expirationTime}" pattern="yyyy-MM-dd HH:mm"/></td>

                                <td>
                                    <c:set var="currentTime" value="<%=new Date() %>" property="yyyy-MM-dd HH:mm"></c:set>
                                    <c:choose>
                                        <c:when test="${currentTime < member.expirationTime}">
                                            <span style="color: #0C0C0C;">使用中</span>
                                        </c:when>
                                        <c:when test="${currentTime > member.expirationTime}">
                                            <span style="color: #999999;">已到期</span>
                                        </c:when>
                                    </c:choose>
                                </td>
                                <td class="tb-opts">
                                    <div class="comm-opts">
                                        <a href="${ctx}/system/member/partnerForm.do?id=${member.id}" target="_self">
                                            编辑
                                        </a>
                                        <a target="_self"
                                           href="javascript:openDialog('分配角色-${member.realname}','${ctx}/system/role/distributionRole.do?memberId=${member.id}&identity=partner&isNew=true','700px','500px')">
                                            分配角色
                                        </a>
                                        <a href="javascript:cancelPartner('${member.id}')">取消合作商</a>
                                        <c:if test="${authorizations[varStatus.index] == 0}">
                                            <a class="red" target="_blank"
                                               href="${ctx}/openPlatform/authorization/getAuthorizeUrl.do?memberId=${member.id}">
                                                微信授权
                                            </a>
                                        </c:if>
                                        <c:if test="${authorizations[varStatus.index] == 1}">
                                            <a class="green" target="_blank"
                                               href="${ctx}/openPlatform/authorization/getAuthorizeUrl.do?memberId=${member.id}">
                                                重新授权
                                            </a>
                                        </c:if>
                                        <c:if test="${member.openStatus == 1}">
                                            <a target="_self" class="green"
                                               href="${ctx}/system/member/merchantForm.do?memberId=${member.id}">
                                                修改商户信息
                                            </a>
                                        </c:if>
                                        <c:if test="${member.openStatus == 0}">
                                            <a target="_self" class="red"
                                               href="${ctx}/system/member/merchantForm.do?memberId=${member.id}">
                                                绑定商户信息
                                            </a>
                                        </c:if>
                                        <a target="_self"
                                           href="${ctx}/moneyManagement/allMoneyList.do?memberId=${member.id}">
                                            查看合作商信息
                                        </a>
                                        <a href="javascript:txz.selectInitiatorUtil.openListSetInitiator('${member.id}', 1)"
                                           target="_self">分配所属者</a>
                                        <a target="_self" href="${ctx}/member/group/childList.do?partnerId=${member.id}&type=${type}">
                                            子账号列表
                                        </a>
                                    </div>
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </div>
            </div>
            <div id="page_content" class="page-container"></div>
        </div><!--底部-->
        <%@include file="../../include/footer.jsp" %>
    </section>
    <%@include file="../member/selectInitiatorInclude.jsp" %>
</div>

<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript" src="${ctx}/script/common/table_option.js"></script>

<script type="text/javascript">
    $(function () {

//加载分页
        loadPageNew({
            elem: 'page_content',
            totalCount: '${page.totalCount}',
            limit: '${page.limit}',
            page: '${page.page}'
        });
        var layer;
        layui.use(['laydate', 'layer'], function () {
            var laydate = layui.laydate;
            layer = layui.layer;
            // 查询发布日期
            var start = {
                elem: 'input[name=createStart]'
            };

            var end = {
                elem: 'input[name=createEnd]'
            };
            laydate.render(start);
            laydate.render(end);

            function authorizationOrNot() {
                if ($("#from").val() == 'authorization') {
                    var authorizationSuccess = $("#authorizationSuccess").val();
                    if (0 == authorizationSuccess) {
                        util.layerMsgError("授权失败, 请重新授权")
                    } else if (1 == authorizationSuccess) {
                        util.layerMsgSuccess("授权成功")
                    }
                }
            }

            authorizationOrNot();
        });

        $("#btnSuccessExport").click(function () {
            layer.confirm('确认要导出Excel吗?', {
                icon: 3,
                title: '系统提示'
            }, function (index) {
                var url = "${ctx}/order/order/exportTxzMerchantMember.do";
                var loadIndex = layer.load(1, {
                    shade: [0.1, '#fff'] //0.1透明度的白色背景
                });
                $.post(url, {}, function (res) {
                    top.layer.close(loadIndex);
                    if (res.success) {
                        window.location.href = res.data;
                    } else {
                        util.layerMsgError(res.description)
                    }
                });
                top.layer.close(index);
            });
        });
    })

    function openDialog(title, url, width, height, target) {
        layer.open({
            type: 2,
            area: [width, height],
            title: title,
            maxmin: true, //开启最大化最小化按钮
            content: url,
            btn: ['确定', '关闭'],
            yes: function (index, layero) {
                var body = layer.getChildFrame('body', index);
                var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                var inputForm = body.find('#inputForm');
                var top_iframe;
                if (target) {
                    top_iframe = target;//如果指定了iframe，则在改frame中跳转
                } else {
                    top_iframe = '_parent';//获取当前active的tab的iframe
                }
                inputForm.attr("target", top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示

                if (iframeWin.contentWindow.doSubmit()) {
                    setTimeout(function () {
                        top.layer.close(index);
                    }, 100);//延时0.1秒，对应360 7.1版本bug

                    setTimeout(function () {
                        window.location.reload();
                    }, 200);
                }

            },
            cancel: function (index) {
            }
        });
    }

    function verify(content, status, targetId) {
        layer.confirm(content, {icon: 3, title: '系统提示'}, function (index) {
            $.post('${ctx}/system/member/verify.do', {id: targetId, userStatus: status}, function (res) {
                if (res.success) {
                    util.layerMsgSuccess("操作成功", function () {
                        location.reload();
                    });
                } else {
                    util.layerMsgError("操作失败")
                }
            });
        });
    }

    function cancelPartner(id) {
        layer.confirm('确定要取消合作商吗？', {icon: 3, title: '系统提示'}, function (index) {
            $.post('${ctx}/system/member/cancelPartner.do', {id: id, isPartner: 0}, function (res) {
                if (res.success) {
                    util.layerMsgSuccess("操作成功", function () {
                        location.reload();
                    });
                } else {
                    util.layerMsgError("操作失败")
                }
            });
        });
    }
</script>
<script type="text/javascript">
    txz.initHeader({
        nav: [{
            name: '合作商管理',
            curr: true
        }],
        info: '<span class="f12">共<b id="totalCount">${page.totalCount}</b>条记录</span>',
        btns: [{
            name: '添加合作商',
            href: '${ctx}/system/member/partnerForm.do',
            icon: 'add'
        }]
    });
</script>
</body>
</html>